//package com.kuang.demo.config;
//import com.google.gson.Gson;
//import com.qiniu.common.Zone;
//import com.qiniu.storage.BucketManager;
//import com.qiniu.storage.UploadManager;
//import com.qiniu.util.Auth;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.boot.autoconfigure.web.servlet.MultipartProperties;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.boot.web.servlet.MultipartConfigFactory;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.multipart.MultipartResolver;
//import org.springframework.web.multipart.support.StandardServletMultipartResolver;
//import org.springframework.web.servlet.DispatcherServlet;
//
//import javax.servlet.MultipartConfigElement;
//import javax.servlet.Servlet;
//import java.io.File;
//
//@Configuration
//@ConditionalOnClass({Servlet.class, StandardServletMultipartResolver.class, MultipartConfigElement.class})
//@ConditionalOnProperty(prefix = "spring.http.multipart", name = "enabled", matchIfMissing = true)
//@EnableConfigurationProperties(MultipartProperties.class)
//public class FileUploadConfig {
//
//
//    private final MultipartProperties multipartProperties;
//
//    @Value("${baseUploadUrl}")
//    private String baseUploadUrl;
//
//    @Value("${qiniu.accessKey}")
//    private String accessKey;
//
//    @Value("${qiniu.secretKey}")
//    private String secretKey;
//
//    public FileUploadConfig(MultipartProperties multipartProperties) {
//        this.multipartProperties = multipartProperties;
//    }
//
//    /**
//     * 上传配置
//     */
//    @Bean
//    @ConditionalOnMissingBean
//    public MultipartConfigElement multipartConfigElement() {
//        MultipartConfigFactory factory = new MultipartConfigFactory();
//        judge(baseUploadUrl);
//        factory.setLocation(baseUploadUrl);
//        return factory.createMultipartConfig();
//    }
//
//    public void judge(String filePath){
//        File file = new File(filePath);
//        if(!file.exists()){
//            file.mkdir();
//        }
//    }
//
//    /**
//     * 注册解析器
//     */
//    @Bean(name = DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME)
//    @ConditionalOnMissingBean(MultipartResolver.class)
//    public StandardServletMultipartResolver multipartResolver() {
//        StandardServletMultipartResolver multipartResolver = new StandardServletMultipartResolver();
//        multipartResolver.setResolveLazily(this.multipartProperties.isResolveLazily());
//        return multipartResolver;
//    }
//
//    /**
//     * 华东机房
//     */
//    @Bean
//    public com.qiniu.storage.Configuration qiniuConfig() {
//        return new com.qiniu.storage.Configuration(Zone.zone0());
//    }
//
//    /**
//     * 构建一个七牛上传工具实例
//     */
//    @Bean
//    public UploadManager uploadManager() {
//        return new UploadManager(qiniuConfig());
//    }
//
//
//    /**
//     * 认证信息实例
//     *
//     * @return
//     */
//    @Bean
//    public Auth auth() {
//        return Auth.create(accessKey, secretKey);
//    }
//
//    /**
//     * 构建七牛空间管理实例
//     */
//    @Bean
//    public BucketManager bucketManager() {
//        return new BucketManager(auth(), qiniuConfig());
//    }
//
//    /**
//     * 配置gson为json解析工具
//     *
//     * @return
//     */
//    @Bean
//    public Gson gson() {
//        return new Gson();
//    }
//}
